package presentation.controller;

import exceptions.GameNotExistingException;
import application.GameInfoProvider;
import application.GameStarter;
import application.ServerInfoProvider;
import application.parser.Parser;
import application.parser.StringParser;

public class User extends HttpBaseController {

	/**
	 * processes the administrative tasks
	 */
	public void process() {
		String target = "";
		try {
			if (m_Arguments.get("task").equalsIgnoreCase("overview")) {
				m_Request.setAttribute("games", new ServerInfoProvider().getGameValues());
				target = "userscore.jsp";
			} else if (m_Arguments.get("task").equalsIgnoreCase("userscore")) {
	
				int gameId = Integer.parseInt(m_Arguments.get("game"));
				m_Request.setAttribute("hunters", new GameInfoProvider(gameId).getHunterValues());
				target = "score2.jsp";
			} else if (m_Arguments.get("task").equalsIgnoreCase("adminscore")) {
	
				int gameId = Integer.parseInt(m_Arguments.get("game"));
				m_Request.setAttribute("hunters", new GameInfoProvider(gameId).getHunterValues());
				target = "score.jsp";
			}
		} catch (GameNotExistingException e) {
			target = "index.jsp";
		}	
		

		if (m_Arguments.get("task").equalsIgnoreCase("mobilescore")) {
			StringParser parse = new StringParser();
			try {
			int gameId = Integer.parseInt(m_Arguments.get("game"));

		
			new GameInfoProvider(gameId).getHunterValues(parse);
			
			
			
			
			} catch (GameNotExistingException e) {
				parse.add(e);
			}
			m_Request.setAttribute("responseStr", parse.parse());
			target = "response.jsp";
		}

		redirect(target);
	}

}
